
public class HolePerRowFeature implements Feature {

	@Override
	public double computeScore(Stateview s) {
		int[][] field = s.getField();
		int[]top = s.getTop();
		
		int minHeight = 100;
		int weight = 0;
		
		//Only compute rows which are fully filled. 
		for(int i = 0; i < top.length; i++)
		{
			if(minHeight > top[i]) minHeight = top[i];
		}
		
		for(int row = 0; row < minHeight; row++)
		{
			int unconnectedHoles = 0;
			for(int col = 0; col < Stateview.COLS; col++)
			{
				if(field[row][col] == 0)
				{
					unconnectedHoles++;
					
					while(++col < Stateview.COLS && field[row][col] == 0);
				}
			}
			
			/* Comment/ Uncomment
			
			//Higher rows have higher penalty
			unconnectedHoles *= row; 
			
			//Quadratic increase
			unconnectedHoles *= unconnectedHoles;
			
			*/
			
			weight += unconnectedHoles;
		}
		return -weight*20;
	}
	

}
